{include file="admin/header.htm"}
<body>
    <form action="{$smarty.const.ADMIN_NAME}?m=admin&c=block&a=add_tpl" method="post" name="myform">
    <table cellpadding="2" cellspacing="1" class="table_form">
        <caption>添加模版</caption>
        <tr>
            <th><strong>模版名称</strong></th>
            <td><input type="text" name="tpl_name" value="{$tpl.tpl_name}"></td>
        </tr>
        <tr>
            <th><strong>模版结构</strong></th>
            <td id="wrap">
                {if !$tpl || empty($tpl.tpl_fields)}
                <p><input type="text" name="fields[]"><a href="javascript:;" onclick="add()">添加</a>(字段名#字段显示名称#字段类型[text、date、file])</p>
                {else}
                {$index=0}
                {foreach $tpl.tpl_fields as $k => $v}
                <p><input type="text" name="fields[]" value="{$k}#{$v.name}#{$v.type}">{if $index eq 0}<a href="javascript:;" onclick="add()">添加</a>(字段名#字段显示名称#字段类型[text、date、file]){else}<a href="javascript:;" onclick="del(this)">删除</a>{/if}</p>
                {$index=$index+1}
                {/foreach}
                {/if}
            </td>
        </tr>
        <tr>
            <th></th>
            <td><input type="submit" name="doadd" value="添加" class="button_style"></td>
        </tr>
    </table>
    <input type="hidden" name="id" value="{$id}">
    </form>
    <div style="margin:5px 5px;color:red;">注：如果模版只有一个字段且字段类型为file会出错</div>
{include file="admin/footer.htm"}
<script type="text/javascript">
function add() {
    $('#wrap').append('<p><input type="text" name="fields[]"><a href="javascript:;" onclick="del(this)">删除</a>');
}

function del(obj) {
    $(obj).parent().remove();
}
</script>